package com.cl.code.database.mbp.processor;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.cl.code.common.component.processor.GenericBeanPostProcessor;
import com.cl.code.common.constant.FixedFieldConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author chengliang
 * @since 1.0.0
 */
@Slf4j
@Component
public class MybatisPlusPropertiesPostProcessor extends GenericBeanPostProcessor<MybatisPlusProperties> {

    @Override
    public MybatisPlusProperties postProcessAfterInit(MybatisPlusProperties mybatisPlusProperties, String beanName) {
        log.info("Processing MybatisPlusProperties");
        GlobalConfig globalConfig = mybatisPlusProperties.getGlobalConfig();

        GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
        // 设置全局逻辑删除字段
        dbConfig.setLogicDeleteField(FixedFieldConstant.DELETED);
        dbConfig.setLogicDeleteValue("UNIX_TIMESTAMP() * 1000");
        dbConfig.setLogicNotDeleteValue("null");

        // 关闭Banner输出
        globalConfig.setBanner(false);

        return mybatisPlusProperties;
    }

}
